import { Body,Query, Controller, Get, Post, Req, Res, Param, Module,Put, Delete } from '@nestjs/common';
import { JwtAuthGuard } from '../auth/jwt-auth.guard';
import { UseGuards } from '@nestjs/common'
import { RolesService } from '../roles/roles.service'
import { Roles } from '../entity/roles.entity'
import { PageInit,PageNation } from 'src/interface/page.interface';
@Controller('roles')
export class RolesController {
     constructor(private rolesRepository: RolesService) {

        }
        @UseGuards(JwtAuthGuard)
        @Post('create')
        async create(@Body() role: Roles) {
            try {
               return  this.rolesRepository.create(role)
            } catch (error) {
                return {
                    code: 500,
                    msg:error
                }
            }
        }

        @UseGuards(JwtAuthGuard)
        @Put('update')
        async update(@Body() roles: Roles){
            let res = await this.rolesRepository.update(roles);
            console.log('输出返回结构：', res)
            if (res.role_id) {
                return {
                    data: '返回成功',
                    code:1000,
                }
            } else {
                return {
                     data: '返回失败',
                     code:500,
                }
            }
        }

        @UseGuards(JwtAuthGuard)
        @Get('findAll')
        async findAll(@Query() query:PageInit) {
            // console.log('输出take：',query)
            let res = await this.rolesRepository.findAll(query);
            return res;
        }
}
